// import BindCall from "../BindCall";

export default class WatchMap<T> implements Map<string, T>{

    private father: Set<WatchMap<any>> = new Set();

    private dataMap = new Map<string, T>();

    // private call = new BindCall<string[]>();

    public get size(): number {
        return this.dataMap.size;
    }

    public get [Symbol.toStringTag](): string {
        return "[class WatchMap]";
    }

    public has(key: string): boolean {
        return this.dataMap.has(key);
    }

    public get(key: string): T | undefined {
        return this.dataMap.get(key);
    }

    public set(key: string, value: T): this {
        this.dataMap.set(key, value);
        if (value instanceof WatchMap) {
            value.father.add(this);
        }
        return this;
    }

    public clear(): void {
        this.dataMap.clear();
    }

    public delete(key: string): boolean {
        const item = this.dataMap.get(key);
        if (item instanceof WatchMap) {
            item.father.delete(this);
        }
        return this.dataMap.delete(key);
    }

    public forEach(callbackfn: (value: T, key: string, map: Map<string, T>) => void, thisArg?: any): void {
        this.dataMap.forEach(callbackfn, thisArg);
    }

    public entries(): IterableIterator<[string, T]> {
        return this.dataMap.entries();
    }

    public keys(): IterableIterator<string> {
        return this.dataMap.keys();
    }

    public values(): IterableIterator<T> {
        return this.dataMap.values();
    }

    public [Symbol.iterator](): IterableIterator<[string, T]> {
        return this.dataMap[Symbol.iterator]();
    }
}